<template>
	<view>
		<view class="content">
			<view class="list">
				<view class="row">
					<view class="title">头像</view>
					<view class="right"><view class="tis">
					<image v-lazy="userState.headimgurl" mode="widthFix"></image>
					</view><view class="icon">&#xe62d;</view></view>
				</view>
				<view class="row" @click="goto('edit', {data: userState.nickname, type: 'nickname'})">
					<view class="title">昵称</view>
					<view class="right"><view class="tis">{{userState.nickname}}</view>
					<view class="icon">&#xe62d;</view></view>
				</view>
				<view class="row"  @click="goto('edit', {data: wechat, type: 'wechat'})">
					<view class="title">微信号</view>
					<view class="right">
						<view class="tis">{{wechat}}
						</view>
						<view class="icon">&#xe62d;</view>
					</view>
				</view>
				<view class="row" @click="goto('edit', {data: userState.qq, type: 'qq'})">
					<view class="title">QQ号</view>
					<view class="right">
					<view class="tis">{{userState.qq}}</view>
					<view class="icon">&#xe62d;</view>
					</view>
				</view>
			</view>
			<view class="list">
<!-- 				<view class="row" @click="goto('edit', {data: userState.userName, type: 'userName'})">
					<view class="title">真实姓名</view>
					<view class="right">
						<view class="tis">{{userState.userName}}</view>
						<view class="icon">&#xe62d;</view>
					</view>
				</view> -->
				<picker @change="bindPickerChange" :value="userState.sex" :range="array">
					<view class="row row1">
						<view class="title">性别</view>
						<view class="right">
							<view class="tis">
								{{array[userState.sex]}}
							</view>
							<view class="icon">&#xe62d;</view>
						</view>
					</view>
				</picker>
				<picker mode="date" :value="userState.birthday" :start="startDate" :end="endDate" @change="bindDateChange">
					<view class="row"> 
						<view class="title">生日</view>
						<view class="right">
							<view class="tis">{{userState.birthday}}
							</view>
							<view class="icon">&#xe62d;</view>
						</view>
					</view>
				</picker>
			</view>
		</view>
	</view>
</template>

<script>
function getDate(type) {
	const date = new Date();

	let year = date.getFullYear();
	let month = date.getMonth() + 1;
	let day = date.getDate();

	if (type === 'start') {
		year = year - 60;
	} else if (type === 'end') {
		year = year;
	}
	month = month > 9 ? month : '0' + month;;
	day = day > 9 ? day : '0' + day;

	return `${year}-${month}-${day}`;
}	
	import {  
	    mapState,
		mapActions
	} from 'vuex';  
	export default {
		data() {
			return {
				startDate:getDate('start'),
				endDate:getDate('end'),
				array: ['', '男', '女'],
			};
		},
		components: {
		},
		computed: {  
		    ...mapState(['userState']),
			wechat() {
				return this.$store.state.userState.wechat
			}
		},
		methods: {
			showType(tbIndex){
				this.tabbarIndex = tbIndex;
				this.list = this.orderList[tbIndex];
			},
			goto (name, param = {}) {
				this.$openRouter({
					url: `./${name}/${name}`,
					query: param
				})
			},
			onCancel(e) {
				console.log(e)
			},
			onConfirm(e) {
				console.log('kkka:', e)
				this.sex = e.value[0]
			},
			bindDateChange: function(e) {
				this.birthday = e.target.value
				this.reviseInfo({key: 'birthday', value: e.target.value})
			},
			bindPickerChange: function(e) {
				this.reviseInfo({key: 'sex', value: e.target.value})
			},			
			...mapActions({
				reviseInfo: 'REVISE_INFO'
			})
		},
		onLoad() {
		}			
	}
</script>

<style lang="scss">
page{
	background-color: #f3f3f3;	
}
@font-face {
	font-family: 'iconfont';
	src: url('../../css/font/iconfont.eot');
	src: url('../../css/font/iconfont.eot?#iefix') format('embedded-opentype'),
	url('../../css/font/iconfont.woff') format('woff'),
	url('../../css/font/iconfont.ttf') format('truetype'),
	url('../../css/font/iconfont.svg#iconfont') format('svg');
}
.icon {
	font-family:"iconfont" !important;
	font-weight: 200;
	font-size: 30upx;
	font-style:normal;
	-webkit-font-smoothing: antialiased;
	-webkit-text-stroke-width: 0.2px;
	-moz-osx-font-smoothing: grayscale;
	cursor: pointer;
	&:hover {
		color:linear-gradient( 135deg, #FDD819 10%, #E80505 100%);
	}
}

.content{
	padding-bottom: 20upx;
	.list{
		width: 96%;
		padding-left: 4%;
		background-color: #fff;
		margin-bottom: 20upx;
		.row{
			widows: 100%;
			min-height: 90upx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			border-bottom: solid 1upx #eee;
			&:last-child{
				border-bottom: none;
			}
			.title{
				font-size: 32upx;
				color: #333;
			}
			.right{
				display: flex;
				align-items: center;
				color: #999;
				.tis{
					font-size: 26upx;
					margin-right: 5upx;
					max-height: 120upx;
					image{
						width: 100upx;
						height: 100upx;
						border-radius: 100%;
						margin: 10upx 0;
					}
				}
				.icon{
					width: 40upx;
					color: #cecece;
				}
			}
		}
		.row1 {
			&:last-child{
				border-bottom: solid 1upx #eee !important;
			}
		}
	}
}

</style>
